<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="dice">
    <meta name="author" content="weina">
    <title>home list</title>
    <link rel="stylesheet" href="/css/bootstrap.css">
    <link rel="stylesheet" href="/css/select2.min.css">
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/bootstrap.js"></script>
    <script src="/js/select2.min.js"></script>
</head>
<body>
<div class="container" style="margin-top: 100px">

    <div class="form-horizontal " style="margin-bottom: 100px;">
        <fieldset class="form-group row">
            <label class="col-md-5 form-control-label"></label>
            <div class="col-md-5">
                <button class="btnShowResult btn btn-primary">show result</button>
            </div>
        </fieldset>
    </div>

    <div class="container">
        <div class="list-group playerResult">
        </div>
    </div>
</div>
<input th:type="hidden" th:value="${room.roomNumber}" class="inputRoomNumber">
<input th:type="hidden" th:value="${room.roomOwnerName}" class="inputRoomOwnerName">

<script type="text/javascript">
    var htmlData = new Array();

    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $(".btnShowResult").trigger("click");
        }
    });

    $('.btnShowResult').bind('click', function () {
        showResult();
    });

    function showResult() {
        var roomNumber = $(".inputRoomNumber").val();
        var roomOwnerName = $(".inputRoomOwnerName").val();
        var param = {roomNumber: roomNumber, roomOwnerName: roomOwnerName};
        $.ajax({
            type: "POST",
            url: "/roomOwner/showResult",
            data: JSON.stringify(param),
            dataType: "json",
            contentType: "application/json",
            success: function (data) {
                if (data.result === "success" && data.bizCode==="E_0000") {
                    $.each(data.data, function (index, v) {
                        var htmlStr = new Array();
                        htmlStr.push("<div class=\"list-group-item\">");
                        htmlStr.push("<h4 class=\"list-group-item-heading\">player : " + v.playerName + "</h4>");
                        htmlStr.push("<h4 class=\"list-group-item-text\">dice : " + v.diceNumber + "</h4>");
                        htmlStr.push("</div>");
                        htmlData.push(htmlStr.join(""));
                    });
                    $(".playerResult").html(htmlData.join(""));
                } else {
                    alert(data.bizMsg);
                }
            }
        });
    }

</script>
</body>
</html>